package com.huazi.user.registration.dao.imp;

import com.huazi.user.registration.dao.LoginI;
import com.huazi.user.registration.entity.Ct_user;
import com.huazi.user.registration.entity.User;
import com.huazi.user.registration.tool.BaseDao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 登录账号的方法
 */
public class LoginImpl extends BaseDao implements LoginI {
    ResultSet rs = null;

    /**

     * @return
     */
//    @Override
//    public boolean register(String account, String pwd) {
//        int count = 0;
//        //new出Stringbuffer对象填入sql
//        StringBuffer sql = new StringBuffer("select count(1) from frontdesk_card where password=? and   ");
//        if (account.length() == 5) {//复合条件拼接sql
//            sql.append(" id=?");
//            rs = excuteQuery(sql.toString(), pwd, account);//转为String 调用方法返回result对象
//            try {//遍历对象获得值
//                while (rs.next()) {
//                    count = rs.getInt(1);
//                }
//                if (count == 1) {
//                    return true;//登陆成功返回值
//                }
//            } catch (SQLException sqlException) {
//                sqlException.printStackTrace();
//            }
//        } else if (account.length() == 18) {
//            sql.append(" idCard=?");
//            rs = excuteQuery(sql.toString(), pwd, account);
//            try {
//                while (rs.next()) {
//                    count = rs.getInt(1);
//                }
//                if (count == 1) {
//                    return true;
//                }
//            } catch (SQLException sqlException) {
//                sqlException.printStackTrace();
//            }
//        }
//
//
//        return false;
//    }

    @Override
    public Integer register(Map<String, Object> map) {
        return null;
    }

    /**
     * 查询用户信息的方法
     *
     * @param account 账号
     * @return
     */
    @Override
    public User result(Integer account) {
//        //根据账号返回结果
//        StringBuffer sql = new StringBuffer("select id,password,idCard,name,phone,sex,age,money,id from hospital.frontdesk_card where 1=1 ");
//        User user = null;
//        if (account.length() == 5) {
//            sql.append(" and id=?");
//            rs = excuteQuery(sql.toString(), account);
//            try {
//                while (rs.next()) {
//                    //Integer id, String pwd, String idCard, String name, String sex, String phone, Integer age, Double money
//                    Integer id = rs.getInt(1);
//                    String pwd = rs.getString(2);
//                    String Idcard = rs.getString(3);
//                    String name = rs.getString(4);
//                    String phone = rs.getString(5);
//                    String sex = rs.getString(6);
//                    Integer age = rs.getInt(7);
//                    double money = rs.getDouble(8);
//                    user = new User(id, pwd, Idcard, name, sex, phone, age, money);
//                }
//            } catch (SQLException sqlException) {
//                sqlException.printStackTrace();
//            }
//        } else if (account.length() == 18) {
//            sql.append(" and idCard=?");
//            rs = excuteQuery(sql.toString(), account);
//            try {
//                while (rs.next()) {
//                    Integer id = rs.getInt(1);
//                    String pwd = rs.getString(2);
//                    String Idcard = rs.getString(3);
//                    String name = rs.getString(4);
//                    String sex = rs.getString(5);
//                    String phone = rs.getString(6);
//                    Integer age = rs.getInt(7);
//                    double money = rs.getDouble(8);
//                    user = new User(id, pwd, Idcard, name, sex, phone, age, money);
//                }
//            } catch (SQLException sqlException) {
//                sqlException.printStackTrace();
//            }
//        }
//

        return null;
    }

    /**
     * 查询ct检查报告的方法
     *
     * @param account
     * @return
     */
    @Override
    public List<Ct_user> resultCt(String account) {
        List<Ct_user> list = new ArrayList<>();
        Ct_user user = null;
        String sql = "SELECT CuserName,CTime,inspectionItem,doctorname,diagnose FROM `department_ct` dc,doctor_information di where dc.doctorid=di.doctorId AND CdiagnoseNO=?";
        rs = excuteQuery(sql, account);
        try {
            while (rs.next()) {
                String uanme = rs.getString(1);
                String part = rs.getString(2);
                String type = rs.getString(3);
                String doctor = rs.getString(4);
                String time = rs.getString(5);
                user = new Ct_user(uanme, part, type, doctor, time);
                list.add(user);
            }
        } catch (SQLException sqlException) {
            System.out.println("胡振是煞笔");
        }
        return list;
    }
}
